//
//  LabelAndCollectionReusableView.m
//  UI14_banTang Practice
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "LabelAndCollectionReusableView.h"
#define kCOLL @"REUSE"

@interface LabelAndCollectionReusableView () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UICollectionView *collectionView;

@end


@implementation LabelAndCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 50)];
        self.label.text = @"分类";
        self.label.backgroundColor = [UIColor redColor];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumInteritemSpacing = 2.5;
        layout.minimumLineSpacing = 10;
        layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
        CGFloat height = CGRectGetHeight(frame) - 50 - 40; // 3个item高度
        layout.itemSize = CGSizeMake((frame.size.width - 30) / 2, height / 3);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, frame.size.width, CGRectGetHeight(frame) - 50) collectionViewLayout:layout];
        self.collectionView.backgroundColor = [UIColor redColor];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        self.collectionView.pagingEnabled = YES;
        
        [self addSubview:self.label];
        [self addSubview:self.collectionView];
        
        [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCOLL];
    }
        return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCOLL forIndexPath:indexPath];
    cell.backgroundColor = [UIColor yellowColor];
    return cell;
}





@end
